
/*
* 路径跳转
* */
let userAccount=document.getElementById("user_account").addEventListener("click",()=>{
    document.location="./UserAccount.html"
})
let contact =document.getElementById("contact").addEventListener("click",()=>{
    document.location="./UserContact.html"
})
let tasks =document.getElementById("tasks").addEventListener("click",()=>{
    document.location="./UserTasks.html"
})
let backToUserDashboard=document.getElementById("backToUserDashboard")
if(backToUserDashboard)  {
    backToUserDashboard.addEventListener("click", () => {
        document.location = "./UserDashboard.html"
    })
}
let changeNightModeStatus = document.getElementById("NightModeBGI").addEventListener("click", (event) => {


    if (event.target.style.backgroundImage == "url(\"../images/close.svg\")") {
        event.target.style.backgroundImage = "url('../images/open.svg')"
        document.getElementById("html").style.backgroundImage = "url('../images/bgIMG_night.jpg')"
        Cookies.set("nightmode","1")
    } else {

        event.target.style.backgroundImage = "url('../images/close.svg')"
        document.getElementById("html").style.backgroundImage = "url('../images/bgIMG.jpg')"
        Cookies.set("nightmode","0")
    }

})
let userlogout = document.getElementById("userLogout");
userlogout.addEventListener("click", (event => {
    $.post("/pub/userLogout",
        null,
        function (res) {
            if (res.status.startsWith("4")) {
                alert(res.message)
                document.location = "/public/html/home.html"
            } else {
                alert(res.message)
                document.location = "/public/html/home.html"
            }
        }, "json");
}))

window.addEventListener("load",()=> {
    let userLoginNumberAndName = document.getElementById("userLoginNumberAndName")
    if (userLoginNumberAndName) {
        userLoginNumberAndName.innerText = `User ID:${Cookies.get('id')} Name:${Cookies.get('username')}`
    }

if(Cookies.get("nightmode")==1) {
    document.getElementById("NightModeBGI").style.backgroundImage = "url('../images/open.svg')"
    document.getElementById("html").style.backgroundImage = "url('../images/bgIMG_night.jpg')"
}
else {
    document.getElementById("NightModeBGI").style.backgroundImage = "url('../images/close.svg')"
    document.getElementById("html").style.backgroundImage = "url('../images/bgIMG.jpg')"
}




})


